package com.example.lawyer.databind.assembly;

import android.os.Build;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableField;

import com.example.lawyer.BR;
import com.example.lawyer.R;
import com.example.lawyer.adapter.CurrentAdapters;
import com.example.lawyer.databind.itemview.TypeGridItemViewData;
import com.example.lawyer.factory.AutoHeightGridTool;

import java.util.List;

/***
 * 分类数据模型
 */

public class TypeGridData {


    public ObservableField<List<TypeGridItemViewData>> griddata = new ObservableField<>();

    @BindingAdapter("setadapter")
    public static void SetGridAdapter(View view,List<TypeGridItemViewData> data)
    {
        if(data==null)
        {
            System.out.println("空的");
            return;
        }
        if(data.size()<1)
        {
            return;
        }
        System.out.println("数量"+data.size());
        CurrentAdapters currentAdapters = new CurrentAdapters<>(data, R.layout.item_assembly_type_grid_view, com.example.lawyer.BR.homeATypeGridItemData);
        GridView gridView = (GridView) view;
        gridView.setAdapter(currentAdapters);
        GridItemClick(gridView);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            new AutoHeightGridTool().GridViewHeightTool(gridView,5);
        }
    }

    //点击事件
    public static void GridItemClick(GridView view)
    {

        view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                System.out.println(position);
                System.out.println(parent.getItemAtPosition(position));
                System.out.println(parent.getChildCount());
                if(position== parent.getChildCount()-1)
                {
                    //更多
                    System.out.println("打开更多");
                    return;
                }

            }

        });

    }


}
